package com.siyue.handler;


import jakarta.websocket.ClientEndpoint;
import jakarta.websocket.OnMessage;
import jakarta.websocket.OnOpen;
import jakarta.websocket.Session;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.WebSocketHttpHeaders;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.client.WebSocketClient;

import java.net.URI;
import java.util.concurrent.CompletableFuture;


@Data
@Component
@ClientEndpoint
@Slf4j
public class MyWebSocketClient implements WebSocketClient {

    private Session session;

    @OnOpen
    public void onOpen(Session session) {
        this.session = session;
        log.info("I1717940964 {} 客户端开启链接", session.getId() );
        session.setMaxIdleTimeout(15 * 1000); // 例如设置15秒超时
    }

    @OnMessage
    public void onMessage(String message) {
        log.info("I1717940964 {} 收到消息", message );
        // 接收消息后的操作
    }

    @Override
    public CompletableFuture<WebSocketSession> execute(WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) {
        return null;
    }

    @Override
    public CompletableFuture<WebSocketSession> execute(WebSocketHandler webSocketHandler, WebSocketHttpHeaders headers, URI uri) {
        return null;
    }

    // 其他生命周期方法...
}
